package cn.dubito.learning.security.core.validator.processor.impl;

import cn.dubito.learning.security.core.validator.code.ImageCode;
import cn.dubito.learning.security.core.validator.code.ValidateCode;
import cn.dubito.learning.security.core.validator.processor.AbstractValidateCodeProcessor;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import javax.imageio.ImageIO;

/**
 * 图片验证码处理器
 * @author liliang
 * @description:
 * @date 2018/5/8.
 */
//@Component("imageCodeProcessor")
public class ImageCodeProcessor extends AbstractValidateCodeProcessor<ImageCode> {

    @Override
    protected void send(ServletWebRequest request, ImageCode imageCode) throws Exception {
        ImageIO.write(imageCode.getImage(), "JPEG", request.getResponse().getOutputStream());
    }
}
